package sg.edu.nus.iss.umpire.dao.jpa;

import java.util.List;

import javax.persistence.EntityManager;
import javax.persistence.Query;

import sg.edu.nus.iss.umpire.dao.SessionDao;
import sg.edu.nus.iss.umpire.domain.CompetitionDay;
import sg.edu.nus.iss.umpire.domain.Session;

public class SessionDaoImpl extends BaseDaoImpl<Long, Session> implements
		SessionDao {

	public SessionDaoImpl(EntityManager em) {
		super(em);
	}


	public List<Session> findSessionByCompetitionDay(CompetitionDay competitionDay) {

			String query = "SELECT FROM "
					+ Session.class.getName()
					+ " session where session.competitionDayKey =:competitionDayKey";
			Query q = em.createQuery(query).setParameter("competitionDayKey",
					competitionDay.getCompetitionDayKey());

			q.setHint("datanucleus.appengine.datastoreReadConsistency",
					"EVENTUAL");
			List<Session> sessions = (List<Session>) q.getResultList();
			return sessions;
	}

//	public void addConfirmedUmpireToSession(Session session,Umpire confirmedUmpire){
//		Session p = (Session) em.find(Session.class, session.getSessionKey());
//		if(p.getConfirmedUmpire() != null){
//	        p.getConfirmedUmpire().add(confirmedUmpire);
//		}else{
//			List<Umpire> umpireList = new ArrayList<Umpire>();
//			umpireList.add(confirmedUmpire);
//			p.setConfirmedUmpire(umpireList);
//		}
//		em.merge(p);
//	}
//	
//	public List<Umpire> getConfirmedUmpireListBySession(Session session){
//		List<Umpire> confirmedUmpireList = new ArrayList<Umpire>();
//		Session p = (Session) em.find(Session.class, session.getSessionKey());
//		confirmedUmpireList = p.getConfirmedUmpire();
//		return confirmedUmpireList;
//	}
//	
//	public void addAvailUmpireToSession(Session session,Umpire availUmpire){
//		Session p = (Session) em.find(Session.class, session.getSessionKey());
//		if(p.getAvailUmpire() != null){
//	        p.getAvailUmpire().add(availUmpire);
//		}else{
//			List<Umpire> umpireList = new ArrayList<Umpire>();
//			umpireList.add(availUmpire);
//			p.setAvailUmpire(umpireList);
//		}
//		em.merge(p);
//	}
//	
//	public List<Umpire> getAvailUmpireListBySession(Session session){
//		List<Umpire> availUmpireList = new ArrayList<Umpire>();
//		Session p = (Session) em.find(Session.class, session.getSessionKey());
//		availUmpireList = p.getAvailUmpire();
//		return availUmpireList;
//	}
	
}
